//参考文章https://blog.csdn.net/xp178171640/article/details/104570081/

#include <sstream>
#include "threadpool.h"
#include "chrono"

using namespace linch;

// 1. 执行函数定义
#define Func(index) \
void func_##index() \
{\
    printf("=========== thread::%u \n",std::this_thread::get_id()); \
}\

Func(1)
Func(2)
Func(3)
Func(4)

//2. 执行任务入队列
#define RUN_IN_POOL(index) \
do{ pool.run(std::function<void()>(&func_##index)); }while(0)

int main()
{
    ThreadPool pool;
    pool.start(4);
    pool.setMaxQueueSize(3);

    RUN_IN_POOL(1);
    RUN_IN_POOL(2);
    RUN_IN_POOL(3);
    RUN_IN_POOL(4);

    //主线程休眠5秒
    std::this_thread::sleep_for(std::chrono::seconds(2));
    pool.stop();
    std::cout << "Hello World! "<< std::this_thread::get_id() << std::endl;
    return 0;
}
